import { createRouter, createWebHistory } from 'vue-router'
import Home from '../views/home.vue'
import Login from '../views/login.vue'

import Reg from '../views/reg.vue'

import TodoList from '../views/todolist.vue'
import TodoListTable from '../views/todolisttable.vue'
const routes = [
    {
        path: '/',
        name: 'root',
        redirect: { name: 'TodoList' }
    },
    {
        path: '/home',
        name: 'Home',
        component: Home
    },

    {
        path: '/login',
        name: 'Login',
        component: Login
    },

    {
        path: '/reg',
        name: 'Reg',
        component: Reg
    },

    {
        path: '/todolist',
        name: 'TodoList',
        component: TodoList
    },
    {
        path: '/todotable',
        name: 'TodoListTable',
        component: TodoListTable
    }
]
const router = createRouter({
    // 4. 内部提供了 history 模式的实现。
    history: createWebHistory(),
    routes // `routes: routes` 的缩写
})


// router.beforeEach((to, from, next) => {
//     // ...
//     // 返回 false 以取消导航
//     console.log('i am before each!!')

//     const token = localStorage.getItem('token')  //jwt
//     if (to.name != 'Login' && !token) {
//         next({ name: 'Login' })
//     } else {
//         next()
//     }

// })

export default router